'use strict';

angular.module('myApp.teach_new', [])

.controller('teach_newCtrl', ['$scope','$http',
    function($scope,$http) {

    $http.get('v1/teach_content_cat').success(function(data){
        $scope.model = data.result;
          console.log($scope.model);
    });

    $scope.create_cat = function(){
    	var value = {'name':$('#create_cat').val()};
        $http.post('v1/teach_content_cat',value).success(function(data){
            if( !data.error ){
                alert("新增成功","success");
			    $http.get('v1/teach_content_cat').success(function(data){
			        $scope.model = data.result;
			          console.log($scope.model);
			    });             
            }else{
                alert(data.message);
            }
        });
    };

    $scope.submit = function(){
    	var value = {
    		'cat_id':$('#create_cat').val(),
    		'name':$('#create_tittle').val(),
    		'content':$("iframe").contents().find("body").html()
    	};
        console.log(value);
    	$http.post('v1/teach_content_cat/'+$('#create_cat').val()+'/teach_content',value).success(function(data){
            if( !data.error ){
                alert("新增成功","success");
				window.location.href = '#/teach_paper';             
            }else{
                alert(data.message);
            }
        });
    };

	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="content"]', {
			resizeType : 1,
			allowPreviewEmoticons : false,
			allowImageUpload : false,
			items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link']
		});
	});	
}]);